package com.topsun.framework.common.core.util;

/**
 * 
 * @author: 皮皮
 * @date: 2020/11/25 11:18 AM
 */
public class IdUtil extends cn.hutool.core.util.IdUtil {


    private static final IdUtil instance = new IdUtil();

    private int workerId = 0;

    private int datacenterId = 0;

    private IdUtil(){}

    public void setWorkerId(int workerId) {
        this.workerId = workerId;
    }

    public void setDatacenterId(int datacenterId) {
        this.datacenterId = datacenterId;
    }

    public static IdUtil getInstance() {
        return instance;
    }

    public Long getId() {
        return IdUtil.getSnowflake(workerId, datacenterId).nextId();
    }

    public String getIdStr() {
        return IdUtil.getSnowflake(workerId, datacenterId).nextIdStr();
    }
}
